package com.xsm.yygh.cmn.controller;



import com.xsm.yygh.cmn.service.DictService;
import com.xsm.yygh.model.cmn.Dict;
import com.xsm.yygy.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/admin/cmn/dict")
@Api(tags = "数据字典接口")
@Slf4j
@CrossOrigin    // 允许跨域
public class DictController {

    @Autowired
    DictService dictService;

    /**
     * 在dict表里查询parent_id 为id 的所有数据
     */
    @GetMapping("/selectAllDict/{id}")
    @ApiOperation(value = "在dict表里查询parent_id 为id 的所有数据")
    public Result<List<Dict>> selectAllDict(@PathVariable Long id){
        List<Dict> dictAll= dictService.selectAllDict(id);

        return Result.ok(dictAll);
    }


    @GetMapping("/exportDict")
    @ApiOperation(value = "下载")
    public void exportDict(HttpServletResponse response){
        dictService.exportDict(response);

    }

    @PostMapping("/uploading")
    @ApiOperation(value = "上传")
    public Result<Void> uploading(MultipartFile file){
        dictService.uploading(file);

        return Result.ok();
    }

}
